﻿using System.Reflection;

namespace Borg
{
    internal class PlugPlugTask : Task<PlugInfo>
    {
        private readonly SlotInfo _si;
        private readonly bool _isManual;

        public override string Name
        {
            get
            {
                return _si == null
                    ? string.Format("Plug({0})", obj.Name)
                    : string.Format("Plug({0}, {1})", obj.Name, _si.Name);
            }
        }

        public PlugPlugTask(PlugInfo obj, SlotInfo si, bool isManual, uint taskGroupId, Assembly initiator)
            : base(obj, taskGroupId, initiator)
        {
            _si = si;
            _isManual = isManual;
        }

        public override void Execute()
        {
            if (_si == null)
                obj.InternalPlug(taskGroupId, initiator);
            else
                _si.InternalPlug(obj, _isManual, taskGroupId, initiator, true);
        }

        public override string ToString()
        {
            var str = _si == null
                          ? string.Format("{0}: {1}.InternalPlug()", taskGroupId, obj)
                          : string.Format("{0}: {1}.InternalPlug({2}, {3})",
                            (object)taskGroupId, (object)obj, (object)_si, (object)(_isManual ? 1 : 0));

            return str;
        }
    }
}

